<?php
 namespace Home\Controller;
 use Think\Controller;
class RegBusinessController extends Controller {

	public function register(){
		$this->display();
	}
	public function doregister(){
		$data['business_mobile']=I('post.business_mobile','');
		$password['password']=I('post.password','');
		$data['business_password']=I('post.business_password','');
		$data['business_owner']=I('post.business_owner','');
		$data['business_card']=I('post.business_card','');
		$data['business_photos1']=I('post.business_photos1','');
		$data['business_photos2']=I('post.business_photos2','');
		$data['business_name']=I('post.business_name','');
		$data['business_picture']=I('post.business_picture','');
		$data['business_licence']=I('post.business_licence','');
		$data['business_photos']=$data['business_photos1'].'|'.$data['business_photos2'];
		// $code=rand(10000,99999);
		// Vendor('aliyun.sendSms');
  //       $sms = new \Vendor\aliyun\aliSms($data['business_mobile'], $code);
  //       $sms->send();die;
		if(empty($data['business_mobile'])){
			die(json_error('手机号不能为空！'));
		}
		$preg=preg_match("/^0?(13|14|15|17|18)[0-9]{9}$/", $data['business_mobile']);
		if(!$preg){
			die(json_error('手机号格式不正确！'));
		}
		$res=M('business')->where(array('business_mobile'=>$data['business_mobile']))->find();
		if($res){
			die(json_error('该手机号已注册！'));
		}
		$check=preg_match('/^(?![0-9]+$)(?![a-zA-Z]+$){6,16}/',$password['password']);
		if(!$check){
			die(json_error('密码格式不正确！'));
		}
		if($password['password']=='' || $data['business_password']==''){
			die(json_error('密码不能为空！'));
		}
		if($password['password']!==$data['business_password']){
			die(json_error('两次密码不一致！'));
		}
		if(empty($data['business_owner'])){
			die(json_error('姓名不能为空！'));
		}
		if(empty($data['business_card'])){
			die(json_error('身份证号不能为空！'));
		}
		$check_card=preg_match('/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/',$data['business_card']);
		if(!$check_card){
			die(json_error('身份证号码格式不正确！'));
		}
		$password=password($data['business_password']);
		$data['business_password']=md5_pwd($password,$data['business_mobile']);
		if(empty($data['business_photos1'])){
			die(json_error('请添加身份证照片(正反面各一张)！'));
		}
		if(empty($data['business_photos2'])){
			die(json_error('请添加身份证照片(正反面各一张)！'));
		}
		if(empty($data['business_name'])){
			die(json_error('商家名称不能为空！'));
		}
		if(empty($data['business_picture'])){
			die(json_error('商家图标不能为空！'));
		}
		if(empty($data['business_licence'])){
			die(json_error('商家营业执照不能为空！'));
		}
		$business=M('business')->data($data)->add();
		if($business){
			$this->success('您的申请已提交,三个工作日内会有申请结果,请耐心等待！谢谢。');
		}else{
			$this->error('参数错误！');
		}


	}




}